import QtQuick 2.0
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import Quick.SystemComponent.FontLoader 0.1


Page{
    id:root
    title: "Button"


    GridView{
        id:grid
        anchors.fill: parent
        cellHeight:60
        cellWidth:60
        model: creatModel()

        ScrollBar.vertical: ScrollBar { }

        delegate: ColumnLayout{
            spacing: 0

            Text{
                color: "green"
                text: modelData
                font.pixelSize: 20
                Layout.alignment: Qt.AlignHCenter
            }

            ToolButton {
                font.pixelSize: 20
                visible: judgeUnicodeVisible(modelData)
                text: String.fromCharCode(modelData).toString()
                Layout.alignment: Qt.AlignHCenter
                onClicked: {
                    btn.text = text
                    console.log(strToHexCharCode(modelData))
                }
            }
        }

    }

    Row{
        visible: false
        ToolButton{
            id:btn
            width: 100
            height: 100
            font.family: Family.awesome.name
            text: "\u044f"
            onClicked: {
                test(btn.text)
            }
        }

        ToolButton{
            id:btn1
            width: 100
            height: 100
            text: String.fromCharCode(125).toString()

            font.family: Family.awesome.name
            onClicked: {
                console.log(btn.text === btn1.text)
            }
        }
    }

    function creatModel(){
        var array = []
        for(var key = 39;key<=137;key++){
            array.push(key)
        }

        for(key = 708;key<=890;key++){
            array.push(key)
        }

        for(var key1 = 9661;key1<11217;key1++){
            array.push(key1)
        }
        return array
    }



    function judgeUnicodeVisible(index){
        if(index > 37){
            if(index < 897)
                return true
        }
        if(index > 9661)
            return true
        return false
    }



    function strToHexCharCode(str) {
      if(str === "")
        return "";
      var hexCharCode = [];

      if(str.toString(16).length === 1){
            hexCharCode.push("000")
      }
      if(str.toString(16).length === 2){
            hexCharCode.push("00")
      }
      if(str.toString(16).length === 3){
            hexCharCode.push("0")
      }
      hexCharCode.push(str.toString(16))
      return hexCharCode.join("");
    }

    function strToUnicode(str){
        var unicode = []
        unicode.push("\\u")
        unicode.push(str)
        return unicode.join("");
    }


}
